var ipupgrade_location = (window.location.href).split('/');
var basePath = ipupgrade_location[0]+'//'+ipupgrade_location[2]+'/'+ipupgrade_location[3];

//全局ajax控制
$.ajaxSetup({  
    cache: false, //close AJAX cache  
    //contentType:"application/x-www-form-urlencoded;charset=utf-8",
    beforeSend:function(XHR){
    	ajaxBeforeSendFn(XHR);
    },
    complete:function(XHR){
    	ajaxCompleteFn(XHR);
    }   
});

//设置ajax自定义请求头，供服务器进行验证
function ajaxBeforeSendFn(XHR){
	XHR.setRequestHeader("X-Requested-With","XMLHttpRequest");
}

function ajaxCompleteFn(XHR){
    var resJson = $.parseJSON(XHR.responseText);
    //如果ajax请求被拦截，则根据返回的提示信息进行相应的处理
    if(resJson.success == false){
    	intercept(resJson.data);
    }
}

// 拦截处理
function intercept(message){ 
	// session过期
	 if(message == 'SESSION_OUT'){     
		 	alert('用户登录会话已过期，请重新登录！');
		    //setTimeout('window.top.location.href = "login"', 100);
		 	window.top.location.href = "login";
     }
     // 后台异常
     else if(message == 'SYS_EXCEPTION'){ 
     	//alert(resText);
     	window.top.location.href = basePath+"/error.jsp";  
     } 
    
}  

//去字符串左右空格    
function trim(s){ 
	return s.replace(/^\s*/, "").replace(/\s*$/, "");
}
